package com.shujia.five;

import org.junit.Test;

import java.io.*;

public class BufferStreamDemo {

    @Test
    public void test2() {
        try (InputStream is = new FileInputStream("file\\鹿鼎记I_hd.mp4");
             OutputStream os = new FileOutputStream("file\\mp4\\ldj.mp4")) {

            long start = System.currentTimeMillis();

            // 一次读写一个字节数组
            byte[] bys = new byte[1024];
            int len;
            while ((len = is.read(bys)) != -1) {
                os.write(bys, 0, len);
            }
            System.out.println(System.currentTimeMillis() - start);

            os.close();
            is.close();


        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @Test
    public void test1() throws IOException {
        // 默认的缓存数组是8kb, 可以自定义数组的大小
        BufferedInputStream bis = new BufferedInputStream(
                new FileInputStream("file\\鹿鼎记I_hd.mp4"), 16384);

        BufferedOutputStream bos = new BufferedOutputStream(
                new FileOutputStream("file\\mp4\\ldj_2.mp4"), 16384);

        long start = System.currentTimeMillis();
        // 一次读写一个字节数组
        byte[] bys = new byte[1024];
        int len;
        while ((len = bis.read(bys)) != -1) {
            bos.write(bys, 0, len);
        }

        System.out.println(System.currentTimeMillis() - start);

        bos.close();
        bis.close();


    }
}
